package com.gxpt.app.codes;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.CBPageAdapter;
import com.gxpt.app.AppUtils;
import com.gxpt.app.Constant;
import com.gxpt.app.R;
import com.gxpt.app.view.Activity_life_service_detail;
import com.utils.ScreenUtils;
import com.utils.T;
import com.utils.logger.Logger;
import com.utils.picasso.PicassoUtils;

/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子
 */
public class NetworkImageHolderView implements CBPageAdapter.Holder<String>{
    private ImageView imageView;
    Context context;
    @Override
    public View createView(Context context) {
        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return imageView;
    }

    @Override
    public void UpdateUI(final Context context, final int position, String data) {
        imageView.setImageResource(R.mipmap.default_pic);


        int Sviewwidth  = ScreenUtils.getScreenWidth(context);
        int pic_width  = Sviewwidth;
        int pic_hight  = pic_width/16*10;


        //ImageLoader 加载方法
//        ImageLoader.getInstance().displayImage(data,imageView);

        this.context = context;

        if(data.indexOf("#####")>=0){
            final String[] picurl =data.split("#####");
            if(picurl[1].equals("999")){
                imageView.setImageResource(R.mipmap.default_pic);
            }else{
//                Logger.i(""+Constant.IP + picurl[2]);
                PicassoUtils.Picasso_displayImage(context, Constant.IP + picurl[0],pic_width,pic_hight,imageView);

                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//1热门2优质项目3科技陷阱4创新示范项目
                        //点击事件
//                        T.show(context,""+picurl[2],1);

//                        Intent gonew =new Intent();
//                        gonew.setClass(context,Webview_Activity.class);
//                        gonew.putExtra("URL",picurl[2]);
//                        context.startActivity(gonew);

                        Intent gonew =new Intent();
                        gonew.setClass(context,Activity_life_service_detail.class);
                        gonew.putExtra("ID",picurl[2]);
                        context.startActivity(gonew);

                    }
                });
            }
        }


    }

}
